package com.situ.day2;

import org.junit.Test;

public class Homework {

	// 计算9的阶乘 9!=9*8*7*6...*2*1
	@Test
	public void test1() {
		int sum = 1;
		for (int i = 9; i >= 1; i--) {
			System.out.println(i);
			sum = sum * i;
		}
		System.out.println(sum);
	}
	
	// 用for循环输出1—1000之间能被5整除的数，且每行输出3个
	@Test
	public void test2() {
		int count = 0;
		for (int i = 1; i <= 1000; i++) {
			if (i % 5 == 0) {
				System.out.print(i + "\t");
				count++;
				
				if (count % 3 == 0) {
					System.out.println();
				}
			}
		}
	}
	
	@Test
	public void test3() {
		int count = 0;
		for (int i = 1; i <= 1000; i++) {
			if (i % 5 == 0) {
				System.out.print(i + "\t");
				count++;
				
				if (count == 3) {
					System.out.println();
					count = 0;
				}
			}
		}
	}
	
	@Test
	public void test4() {
		for (int i = 1; i <= 1000; i++) {
			if (i % 5 == 0) {
				System.out.print(i + "\t");
			}
			
			if (i % 15 == 0) {
				System.out.println();
			}
		}
	}
	
	// 计算1-100以内所有奇数的和以及所有偶数的和，分别打印出来。
	@Test
	public void test5() {
		int jishuSum = 0;
		int oushuSum = 0;
		for (int i = 1; i <= 100; i++) {
			if (i % 2 == 0) {
				System.out.println(i + "：是偶数");
				oushuSum = oushuSum + i;
			} else {
				System.out.println(i + ": 是奇数");
				jishuSum = jishuSum + i;
			}
		}
		System.out.println("奇数：" + jishuSum);
		System.out.println("偶数：" + oushuSum);
	}
	
}
